/**
* @description: 验收版作业首页
* @author: oahcoay
* @data:
* @remark:
**/
<template>
	<view class="content">
		<view class="nav">
			<view class="left-title">
				<van-icon name="arrow-left" @click="exitBtn" style="margin-right: 4px;vertical-align: middle;" />

				<div>首页</div>
			</view>
		</view>
		<view class="entry-list">
			<view class="menu">
				<view class="module_title">应用管理</view>
				<ul class="module-list">
					<li v-for="(item,index) in moduleList" :key="index" @click="chooseMenu(item,index)">
						<img :src="item.icon">
						<text class="title-menu">{{ item.menuName }}</text>
						<text class="todoNum" v-if="item.menuName === '待办作业' && item.count > 0">{{item.count}}</text>
					</li>
				</ul>
			</view>
		</view>
	</view>
</template>
<script>
  import wx from '../../static/common_js/jweixin_1.0.0'

	import baseConfig from "../../common/config";
	import { mapGetters, mapMutations, mapActions } from 'vuex'
	export default {
		name: 'index',
		components: {},
		props: {},
		data() {
			return {
				moduleList: [
          
        ],
				currentDate: new Date(),
				showDate:true,
				timer: null
			};
		},
		watch: {},
		onShow() {
			this.getUserId()
			if (this.timer) clearInterval(this.timer)
			this.timer = setInterval(()=>{
				this.getTaskGetedList()
			}, 30000)
		},
		computed: {
			...mapGetters(['userData'])
		},
		methods: {
			...mapActions({}),
			chooseMenu(item) {
				// 工单领取 待办工单 工单监控
				switch (item.menuName) {
					case "工单领取": {
						uni.navigateTo({
							url: '/pages/acceptanceVersion/orderList/index?status=non-receive'
						})
						break
					}
					case "待办工单": {
						uni.navigateTo({
							url: `/pages/acceptanceVersion/taskList/index?status=non-finish`
						})
						break
					}
					case "工单监控": {
						uni.navigateTo({
							url: `/pages/acceptanceVersion/taskMonitor/index`
						})
						break
					}
				}

			},
			exitBtn() {
				baseConfig.actions.exitIgw();
			},
			// 获取已经领取的工单
			async getTaskGetedList() {
				let params = {
					userId: this.userData.userId,
					taskState: null,
					interfaceType: 1,
				}
				await this.$apiRequest.ysbApi.getAutumnInspectionTaskListInfo(params).then(res => {
					console.log('需要轨迹队列', res.data.list)
					if (res.data.list.length>0) {
						
						
							let trackList = res.data.list
							trackList.forEach(async (item, index) =>  {
								if(item.tourEndTim&&new Date().getTime()>new Date(item.tourEndTim)){

								}else {
									console.log(`第${index+1}条数据参数如下：`, item)
									let trackType = 0   // 轨迹类型（0：人员轨迹，1：车辆轨迹）
									if (new Date().getTime()>new Date(item.useCarStartTime)&&new Date().getTime()<new Date(item.useCarEndTime)){
										trackType = 1
									}
									if (new Date().getTime()>new Date(item.useCarEndTime)){
										trackType = 0
									}
									console.log(trackType==1?`%c车辆轨迹`:`%c人员轨迹`, 'color: red')
									var taskId = item.objId
									var _this = this
									wx.getLocation({
										type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
										success: function(res) {
											console.log('获取经纬度', res)
											// [res.latitude, res.longitude]
											let params = {
												longitude: res?.longitude,
												latitude: res?.latitude,
												taskId: taskId,
												trackType: trackType
											}
											_this.$apiRequest.ysbApi.insertTrackInfo(params).then(res => {}) // 录入轨迹
										}
									})
								
								
								
							
							}
						})

						


					}
				})
			},
			// 根据用户id查询模块列表数据
			getUserId() {
				let params = {
					userId: this.userData.userId
				}
				this.$apiRequest.ysbApi.selectModelList(params).then(res => {
					// 工单领取 待办工单 工单监控
					res.data.map(item => {
						if (item.menuName === "工单领取") {
							item.icon = require('../../static/standardizedOperationImg/fqjh.png')
						} else if (item.menuName === "待办工单") {
							item.count = res.data.ongoingNum
							item.icon = require('../../static/standardizedOperationImg/dbzy.png')
						} else if (item.menuName === "工单监控") {
							item.icon = require('../../static/standardizedOperationImg/zyjk.png')
						}
					})
					this.moduleList = res.data
				})
			},
		}
	};
</script>
<style scoped lang="scss">
	.content {
		width: 100vw;
		height: 100vh;
		background: #F2F6FA;
		overflow: hidden;

		.nav {
			width: 100vw;
			height: px2vw(163);
			background: #417ADC;

			.left-title {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100%;
				padding: 0 px2vw(40);
				color: #fff;

				div {
					flex: 1;
					text-align: center;
					font-weight: bold;
					line-height: px2vw(50);
					height: px2vw(54);
					font-size: px2vw(54);
				}

				img {
					width: px2vw(44);
					height: px2vw(28);

				}
			}

		}

		.entry-list {
			width: 100vw;
			height: 100%;
			overflow-y: scroll;
			margin-top: px2vw(30);
		}

		.menu {
			width: px2vw(1020);
			height: px2vw(617);
			margin-left: px2vw(30);
			margin-bottom: px2vw(30);
			background-color: #fff;
			border-radius: px2vw(20);
			overflow: hidden;

			.module_title {
				margin: px2vw(40) 0 px2vw(49) px2vw(40);
				font-size: px2vw(40);
				color: #666666;
			}

			.module-list {
				display: flex;
				flex-wrap: wrap;
				align-items: center;
				column-gap: px2vw(85);
				margin-left: px2vw(85);
			}


			li {
				width: px2vw(146);
				margin: 0 0 px2vw(45) 0;
				position: relative;


				img {
					width: px2vw(146);
					height: px2vw(146);
					display: block;
					margin: 0 auto;
				}

				.title-menu {
					font-size: px2vw(36);
					color: #333;
				}

				.todoNum {
					display: inline-block;
					position: absolute;
					top: 0;
					right: 0;
					padding: px2vw(3) px2vw(12);
					background: #f00;
					font-size: px2vw(32);
					color: #fff;
					text-align: center;
					border-radius: px2vw(21);
				}
			}
		}
	}
</style>
